var useFiles = [];

useFiles.push('page.css');
useFiles.push('easyui-icon.css');
useFiles.push('easyloader');

seajs.use(useFiles, function() {
			easyloader.theme = fand.theme;

			easyloader.locale = fand.locale;

			$(initPage);
		});

function initPage() {
	$(document).on("click", 'a[href="#ok"]', ok_click);

	$(document).on("click", 'a[href="#reset"]', reset_click);

	$(document).on("click", 'a[href="#back"]', back_click);
}

function ok_click() {
	using(['form', 'messager', 'tooltip'], function() {
				$.messager.progress();

				$('form').form('submit', {
							onSubmit : function() {
								var isValid = $(this).form('validate');

								if (!isValid) {
									$.messager.progress('close');
								}

								return isValid;
							},
							success : function(data) {
								$.messager.progress('close');

								var jsonData = $.parseJSON(data);

								if (jsonData.message != undefined) {
									$.messager.alert('提示消息', '提交失败:' + jsonData.message, 'error');

									return;
								}

								parent.$('.easyui-datagrid').datagrid('reload');

								back_click();
							}
						});
			});
}

function reset_click() {
	$('form').each(function() {
				this.reset();
			});
}

function back_click() {
	parent.$('#windowForIframe').window('close');
}